package io.geekidea.springbootplus.system.service.impl;

import io.geekidea.springbootplus.system.entity.Carrier;
import io.geekidea.springbootplus.system.mapper.CarrierMapper;
import io.geekidea.springbootplus.system.service.CarrierService;
import io.geekidea.springbootplus.system.param.CarrierPageParam;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.geekidea.springbootplus.framework.common.service.impl.BaseServiceImpl;
import io.geekidea.springbootplus.framework.core.pagination.Paging;
import io.geekidea.springbootplus.framework.core.pagination.PageInfo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.transaction.annotation.Transactional;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;

/**
 *  服务实现类
 *
 * @author miko
 * @since 2020-10-10
 */
@Slf4j
@Service
public class CarrierServiceImpl extends BaseServiceImpl<CarrierMapper, Carrier> implements CarrierService {

    @Autowired
    private CarrierMapper carrierMapper;

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean saveCarrier(Carrier carrier) throws Exception {
        return super.save(carrier);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean updateCarrier(Carrier carrier) throws Exception {
        return super.updateById(carrier);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean deleteCarrier(Long id) throws Exception {
        return super.removeById(id);
    }

    @Override
    public Paging<Carrier> getCarrierPageList(CarrierPageParam carrierPageParam) throws Exception {
        Page<Carrier> page = new PageInfo<>(carrierPageParam, OrderItem.desc(getLambdaColumn(Carrier::getCreateTime)));
        LambdaQueryWrapper<Carrier> wrapper = new LambdaQueryWrapper<>();
        IPage<Carrier> iPage = carrierMapper.selectPage(page, wrapper);
        return new Paging<Carrier>(iPage);
    }

}
